<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateEntityRelationshipsTable extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('entity_relationships', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '实体关联关系表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '实体关联关系表id'])
            ->addColumn('entity_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '实体id'])
            ->addColumn('relation_entity_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '被关联实体id'])
            ->addColumn('uuid', 'char', ['default' => '', 'limit' => 36, 'comment' => '全局唯一标识符'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建人'])
            ->addColumn('created', 'integer', ['signed' => false, 'null' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建时间']);
        $table->create();
    }

    public function down()
    {
        $this->table('entity_relationships')->drop()->save();
    }
}
